﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using System.Web;

/// <summary>
/// JoinActivity 的摘要说明
/// </summary>
public class JoinActivity
{
    public JoinActivity()
    {
    }

    public int JoinActivitys(int ActivityID, int MemID, Chain.Model.SysUser UserModel)
    {
        int flag = 0;

        //1.判断该会员是否参加过此活动
        Chain.BLL.Mem_Activity maBll = new Chain.BLL.Mem_Activity();
        Chain.Model.Mem_Activity maModel = new Chain.Model.Mem_Activity();

        if (maBll.Exists(MemID, ActivityID))
        {

            flag = -13;
        }
        else
        {
            //2.参加活动，插入会员——各种奖励关系表
            Chain.BLL.Activity activity = new Chain.BLL.Activity();
            bool iscovered = activity.IsCovered(ActivityID);

            Chain.BLL.Activity_Gifts awards = new Chain.BLL.Activity_Gifts();
            DataTable dt = awards.GetAwardsInfo(ActivityID);

            List<string> typelist = new List<string>();
            foreach (DataRow dr in dt.Rows)
            {
                typelist.Add(dr["type"].ToString());
            }

            Dictionary<string, Type> dic = new Dictionary<string, Type>();

            dic.Add("积分", typeof(Score));
            dic.Add("储值", typeof(Money));
            dic.Add("推广奖励", typeof(Extend));
            dic.Add("消费返利", typeof(Rebate));
            dic.Add("储值返利", typeof(MoneyRebate));
            dic.Add("分享奖励", typeof(Share));
            dic.Add("小礼品", typeof(Presents));
            dic.Add("代金券", typeof(Ticket));

            Gifts decorator = new Base();
            decorator.MemID = MemID;
            decorator.ActivityID = ActivityID;
            decorator.UserModel = UserModel;
            decorator.IsCovered = iscovered;

            foreach (string item in typelist)
            {
                Type o = dic[item];
                decorator = Activator.CreateInstance(o, decorator) as Decorator;

            }
            flag = decorator.Create();
        }

        return flag;
    }


}